package com.luckyframe.project.jmeter.websocket;

import com.luckyframe.common.constant.GlobalConsts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author junmingyang
 * @date 2018/9/24 7:03 PM
 */
@Controller
public class WebSocketController {

    @Autowired
    private WebSocketManager webSocketManager;

    @MessageMapping(GlobalConsts.HELLO_MAPPING)
    @SendTo(GlobalConsts.TOPIC)
    public ServerMessage graphData(String message) throws Exception {
        return new ServerMessage(message);
    }

    @MessageMapping(GlobalConsts.STATISTIC_MAPPING)
    @SendTo(GlobalConsts.TOPIC_STATISTIC)
    public ServerMessage greeting(String message) throws Exception {
        return new ServerMessage(message);
    }



    @RequestMapping("test")
    public String greeting() throws Exception {
        webSocketManager.publishGraphData("test");

        return "0000";
    }
}
